package ru.study.thinkin.chapter10.gui;

import java.util.Random;


public class GreenhouseControls extends Controller{
	private static GreenhouseControls Instance;
	
	private long greenId = new Random().nextInt(10000);
	
	private boolean light = false;
	private boolean water = false;
	
	private GreenhouseControls() {
		
	}	
	public static synchronized GreenhouseControls getInstance() {
		if (Instance == null)
			Instance = new GreenhouseControls();
		
		return Instance;
	}
	
	public class LightOn extends Event {
		
		public LightOn(long delayTime) {
			super(delayTime);
		}
		@Override
		public void action() {
			//аппаратный вызов
			light = true;			
		}
		@Override
		public String toString() {
			return "свет включен";
		}		
	}
	
	public class LightOff extends Event {
		public LightOff(long delayTime) {
			super(delayTime);
		}
		@Override
		public void action() {
			light=false;
		}
		@Override
		public String toString() {
			
			return "свет выключен";
		}
	}
	
	public class WaterOn extends  Event {
		public WaterOn(long delayTime ) {
			super(delayTime);
		}
		@Override
		public void action() {
			water=true;
		}
		@Override
		public String toString() {
			
			return "вода включена";
		}
	}
	public class WaterOff extends  Event {
		public WaterOff(long delayTime ) {
			super(delayTime);
		}
		@Override
		public void action() {
			water=false;
		}
		@Override
		public String toString() {
			
			return "вода выключена";
		}
	}
	
	public class Bell extends Event {
		public Bell(long delayTime) {
			super(delayTime);
		}
		public void action() {
			//addEvent(new Bell(delayTime));
			System.out.println("Звонок");
		}
		public long getEventId() {
			return id;
		}
		
		public long getConId() {
			return GreenhouseControls.this.con_id;
		}
		public long getGreenId() {
			return GreenhouseControls.this.greenId;
		}
		
		@Override
		public String toString() {
			return "Бам!";
		}
		
	}
	public class Restart extends Event {
		private Event[] eventList;
		public Restart(long delayTime,Event[] eventList) {
			super(delayTime);
			this.eventList = eventList;
			
			/*for(Event e : eventList) {
				addEvent(e);
			}*/
		}
		@Override
		public void action() {
			for(Event e : eventList) {
				e.start();				
				addEventFirst(e);				
			}
			start();
			//addEvent(this);
		}
		public String toString() {
			return "Перезапуск системы";
		}
		
	}
	
	public static class Terminate extends Event {

		public Terminate(long delayTime) {
			super(delayTime);		
		}

		@Override
		public void action() {
			System.exit(0);
			
		}

		@Override
		public String toString() {
			// TODO Auto-generated method stub
			return "отключено";
		}
		
	}
	
}
